#include<bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int T,ans,sum;
set<int> s;
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	T=read();
	while(T--){
		int x=read();
		if(s.count(x)) s.erase(x),sum-=x;
		else s.insert(x),sum+=x;
		int len=s.size();
		if(len<=1){
			puts("0");
			continue;
		}
		int s1=0,s2=0,lst=0,ans=sum-(*s.begin())-1;
		auto it1=s.begin(),it2=--s.end();
		len--;
		while(len){
			s1+=*it1,s2+=*it2;
			++it1,--it2;
			ans-=max(0ll,s1-lst-1);
			lst=s2-1,len--;
		}
		printf("%lld\n",ans);
	}
	return 0;
}